<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>How can I retrieve the text from a GtkMenuItem?</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="GTK+ FAQ"
HREF="book1.html"><LINK
REL="UP"
TITLE="Development with GTK+: widget specific questions"
HREF="c707.html"><LINK
REL="PREVIOUS"
TITLE="How do I add some underlined accelerators to menu
items?"
HREF="x780.html"><LINK
REL="NEXT"
TITLE="How do I right (or otherwise) justify a
GtkLabel?"
HREF="x798.html"></HEAD
><BODY
CLASS="SECT1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>GTK+ FAQ</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="x780.html"
ACCESSKEY="P"
>&#60;&#60;&#60; Previous</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Development with GTK+: widget specific questions</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="x798.html"
ACCESSKEY="N"
>Next &#62;&#62;&#62;</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="AEN788"
>How can I retrieve the text from a GtkMenuItem?</A
></H1
><P
>You can usually retrieve the label of a specific
GtkMenuItem with:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>    if (GTK_BIN (menu_item)-&#62;child)
    {
      GtkWidget *child = GTK_BIN (menu_item)-&#62;child;
  
      /* do stuff with child */
      if (GTK_IS_LABEL (child))
      {
        gchar *text;
    
        gtk_label_get (GTK_LABEL (child), &#38;text);
        g_print ("menu item text: %s\n", text);
      }
    }</PRE
></TD
></TR
></TABLE
><P
>To get the active menu item from a GtkOptionMenu you can
do:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>if (GTK_OPTION_MENU (option_menu)-&#62;menu_item)
{
  GtkWidget *menu_item = GTK_OPTION_MENU (option_menu)-&#62;menu_item;
}</PRE
></TD
></TR
></TABLE
><P
>But, there's a catch. For this specific case, you can
<I
CLASS="EMPHASIS"
>not</I
> get the label widget from
<TT
CLASS="LITERAL"
>menu_item</TT
> with the above code, because the
option menu reparents the menu_item's child temporarily to
display the currently active contents. So to retrive the child
of the currently active menu_item of an option menu, you'll
have to do:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>    if (GTK_BIN (option_menu)-&#62;child)
    {
      GtkWidget *child = GTK_BIN (option_menu)-&#62;child;

      /* do stuff with child */
    }</PRE
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="x780.html"
ACCESSKEY="P"
>&#60;&#60;&#60; Previous</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="book1.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="x798.html"
ACCESSKEY="N"
>Next &#62;&#62;&#62;</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>How do I add some underlined accelerators to menu
items?</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="c707.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>How do I right (or otherwise) justify a
GtkLabel?</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>